package com.masterlau.entry;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;

import java.lang.reflect.Array;
import java.nio.file.OpenOption;
import java.nio.file.StandardOpenOption;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;

import static org.apache.sshd.common.util.GenericUtils.EMPTY_STRING_ARRAY;

final class Helper {
    static final Integer DEF_ORDER = Integer.valueOf("0");
    static final long DEF_HOST_IP = 3232235777L;
    static final int DEF_NUM_OF_MODULE = 1;
    static final int DEF_NUM_OF_SERVER = DEF_NUM_OF_MODULE;
    static final int MAX_NUM_OF_MODULE = 128;
    static final int MAX_NUM_OF_SERVER = MAX_NUM_OF_MODULE;
    static final String[] DEF_MAVEN_BUILD_GOALS = {"clean", "package"};
    static final String[] DEF_MAVEN_PROFILES = EMPTY_STRING_ARRAY;
    static final String MANUAL_CONFIG_HINT = "!!PLEASE EDIT THIS LINE MANUALLY!!";
    static final String NOT_FOUND_HINT = "NOT_FOUND";
    static final String JAVA_HOME_NAME = "JAVA_HOME";
    static final String JRE_HOME_NAME = "JRE_HOME";
    static final String MAVEN_HOME_NAME = "MAVEN_HOME";
    static final String MVN_HOME_NAME = "MVN_HOME";
    static final String M2_HOME_NAME = "M2_HOME";
    static final String EMPTY = "";
    static final String[] DEF_LOG_EXTENSIONS = {".log", ".out"};
    static final int DEF_SERVER_PORT = 22;
    static final String DEF_TEMPLATE_FILE_NAME = "template.json";
    static final String OPTION_G = "g";
    static final String OPTION_GM = "gm";
    static final String OPTION_GS = "gs";
    static final String OPTION_C = "c";
    static final String OPTION_P = "p";
    static final String OPTION_B = "b";
    static final String OPTION_D = "d";
    static final String OPTION_M = "m";
    static final String OPTION_R = "r";
    static final String OPTION_S = "s";
    static final String OPTION_L = "l";
    static final String JDK_JAVA_OPTIONS_KEY = "JDK_JAVA_OPTIONS";
    static final String JDK_JAVA_OPTIONS_VALUE = "-Dfile.encoding=utf-8";
    static final String EXECUTABLE_FILE_EXTENSION = ".jar";
    static final String SCRIPT_FILE_EXTENSION = ".sh";
    static final Duration DEF_TIMEOUT = Duration.ofSeconds(60L);
    static final ObjectMapper OBJECT_MAPPER
            = new ObjectMapper()
            .enable(SerializationFeature.INDENT_OUTPUT)
            .enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)
            .enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
            .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
            .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
            .disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            .registerModule(new AfterburnerModule())
            .setSerializationInclusion(JsonInclude.Include.NON_NULL);
    static final CompletableFuture<?>[] EMPTY_COMPLETABLE_FUTURE_ARRAY = (CompletableFuture<?>[]) Array.newInstance(CompletableFuture.class, 0);
    static final OpenOption[] OPEN_OPTIONS = {StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING};
}
